import java.sql.Connection;
import java.sql.Statement;
import dao.DBUtil;

public class InitDB {
    public static void main(String[] args) throws Exception {
        Connection conn = DBUtil.getConnection();
        Statement st = conn.createStatement();
        st.execute("CREATE TABLE IF NOT EXISTS owner (id INTEGER PRIMARY KEY, name TEXT, phone TEXT)");
        st.execute("CREATE TABLE IF NOT EXISTS house (id TEXT PRIMARY KEY, area REAL)");
        st.execute("CREATE TABLE IF NOT EXISTS property_fee (id INTEGER PRIMARY KEY, houseId TEXT, amount REAL, paid BOOLEAN, dueDate INTEGER)");
        st.execute("CREATE TABLE IF NOT EXISTS parking_space (id INTEGER PRIMARY KEY, type TEXT, ownerId INTEGER, renterId INTEGER, fee REAL)");
        st.execute("CREATE TABLE IF NOT EXISTS own (ownerId INTEGER, houseId TEXT, PRIMARY KEY(ownerId, houseId))");
        st.execute("DELETE FROM owner");
        st.execute("DELETE FROM house");
        st.execute("DELETE FROM property_fee");
        st.execute("DELETE FROM parking_space");
        st.execute("DELETE FROM own");
        st.close();
        conn.close();
        System.out.println("数据库初始化完成");
    }
}
